# !/usr/bin/env python
# -*-coding:utf-8 -*-
"""
@Author : Ayao
@Time   : 2022/5/28
@File   : 寻找旋转排序数组中的最小值.py
"""
from typing import List


class Solution:
    def findMin(self, nums: List[int]) -> int:
        left, right = 0, len(nums) - 1
        while left < right:
            mid = left + (right - left) // 2
            if nums[left] < nums[right]:
                return nums[left]
            elif nums[mid] < nums[left]:
                right = mid
            else:
                left = mid + 1
        return nums[left]


if __name__ == '__main__':
    nums = [3, 4, 5, 1, 2]
    print(Solution().findMin(nums))
    nums = [4, 5, 6, 7, 0, 1, 2]
    print(Solution().findMin(nums))
    nums = [11, 13, 15, 17]
    print(Solution().findMin(nums))
    nums = [2, 3, 4, 5, 1]
    print(Solution().findMin(nums))
    nums = [5, 6, 2, 3, 4]
    print(Solution().findMin(nums))
